package com.forehope.portal.plugins;



import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate;
import com.actionsoft.bpms.commons.portal.skins.AbstPortalSkins;
import com.actionsoft.bpms.commons.portal.skins.PortalSkinsInterface;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.exception.AWSException;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.PortalAPI;

import java.util.LinkedHashMap;
import java.util.Map;

public class ForeHopePCPortal extends AbstPortalSkins implements PortalSkinsInterface {
    /**
     * 登录成功后首页面
     */
    @Override
    public String getHomePage(UserContext me) {
        StringBuilder sb = new StringBuilder();
        // user info
        String userInfo = me.getUserName();
        // template merge
        Map<String, Object> macroLibraries = new LinkedHashMap<String, Object>();
        macroLibraries.put("sid", me.getSessionId());
        macroLibraries.put("portalUrl",SDK.getPortalAPI().getPortalUrl());
        return HtmlPageTemplate.merge("com.awspaas.user.apps.forehope.portal", "index.html", macroLibraries);
    }

    /**
     * 退出提示页面
     */
    public String getLogoutPage(UserContext me) {
        PortalAPI portalApi = SDK.getPortalAPI();
        // 关闭session
        boolean isClosed = portalApi.closeSession(me.getSessionId());
        if (!isClosed) {
            throw new AWSException("Session关闭异常");
        }
        // 调转到你的登出页面
        return "logout sucess!";
    }
}
